using System;
using NUnit.Framework;
using ValidationFramework;

namespace ExampleLibraryCSharp.ParameterValidationManagerExamples
{
	public class ExplicitDelegateExample
	{
		#region Example
		public interface IPerson
		{
			void CheckAge(int age);
		}

		public class Person : IPerson
		{
			readonly Action<int> checkAgeDelegate;

			public Person()
			{
				checkAgeDelegate = ((IPerson)this).CheckAge;
			}
            
			void IPerson.CheckAge(
				[CompareIntRule(5, CompareOperator.LessThan)] int age)
			{
				ParameterValidationManager.ThrowException(this, checkAgeDelegate, age);
				//business code goes here.
			}
		}


		[TestFixture]
		public class ExampleUsage
		{
			[Test]
			[ExpectedException(typeof(ArgumentException))]
			public void RunInvalidData()
			{
				IPerson person = new Person();
				person.CheckAge(7);
			}


			[Test]
			public void RunValidData()
			{
                IPerson person = new Person();
				person.CheckAge(2);
			}
		}
		#endregion
	}
}